
#!/bin/bash

# 定义预期值
EXPECTED_VERSION_ID="1"
EXPECTED_FIRMWARE="Hi3519DV500DMEB_PowerHarmony_PHS_V2.0.0.0"
EXPECTED_FULLNAME="PowerHarmony+ PHS V2.0"

# 获取系统信息 sysphinfo -h 查看使用说明
SYS_INFO=$(sysphinfo -j)
#SYS_INFO=$(sysphinfo -t)
DEV_INFO=$(devinfo -a)

# 提取实际值
ACTUAL_VERSION_ID=$(echo "$SYS_INFO" | grep -oP '"VERSION_ID":\s*"\K[^"]+')
ACTUAL_FIRMWARE=$(echo "$DEV_INFO" | grep -oP '"firmware_version":\s*"\K[^"]+')
ACTUAL_FULLNAME=$(echo "$SYS_INFO" | grep -oP '"NAME":\s*"\K[^"]+')

# 比较函数
compare_field() {
    local field_name=$1
    local expected=$2
    local actual=$3

    if [ "$expected" == "$actual" ]; then
        echo "[OK] $field_name 匹配: $actual"
        return 0
    else
        echo "[ERROR] $field_name 不匹配 (预期: $expected, 实际: $actual)"
        return 1
    fi
}

# 执行检查
echo "开始版本校验..."
compare_field "VERSION_ID" "$EXPECTED_VERSION_ID" "$ACTUAL_VERSION_ID"
compare_field "firmware_version" "$EXPECTED_FIRMWARE" "$ACTUAL_FIRMWARE"
compare_field "const.ohos.fullname" "$EXPECTED_FULLNAME" "$ACTUAL_FULLNAME"

# 汇总结果
if [ $? -eq 0 ]; then
    echo "所有检查项通过"
    exit 0
else
    echo "存在检查项未通过"
    exit 1
fi
